package com.campus.controller;

import com.campus.common.Result;
import com.campus.domain.Dto.ActivityCreateDto;
import com.campus.domain.Dto.ActivitySelectDto;
import com.campus.domain.Dto.ActivityUpdateDto;
import com.campus.service.IActivityService;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/activity")
@Slf4j
public class ActivityController {

    @Autowired
    private IActivityService activityService;

    @PostMapping("/add")
    public Result addActivity(@RequestBody @Validated ActivityCreateDto activityCreateDto){
        int rs = activityService.addActivity(activityCreateDto);
        return rs == 1 ? Result.success() : Result.error();
    }

    @PutMapping("/update")
    public Result updateActivity(@RequestBody @Validated ActivityUpdateDto activityUpdateDto){
        int rs = activityService.updateActivity(activityUpdateDto);
        return rs == 1 ? Result.success() : Result.error();
    }

    @PutMapping("/publish/{id}")
    public Result publishActivity(@PathVariable Integer id){
        int rs = activityService.publish(id);
        return rs == 1 ? Result.success() : Result.error();
    }

    @GetMapping("/page")
    public Result page(ActivitySelectDto activitySelectDto, @NotNull @Validated Integer pageNum, @NotNull @Validated Integer pageSize){
        return Result.success(activityService.page(activitySelectDto,pageNum,pageSize));
    }
}
